QuickOPC User's Guide and Reference
Examples - OPC Unified Architecture - Browsing for data nodes

.NET

// This example shows how to obtain "data nodes" (objects, variables and properties) under the "Objects" node in the address
// space.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.AddressSpace;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class BrowseDataNodes
    {
        public static void Overload1()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object
            var client = new EasyUAClient();

            // Obtain data nodes under "Objects" node.
            UANodeElementCollection nodeElementCollection;
            try
            {
                nodeElementCollection = client.BrowseDataNodes(endpointDescriptor);
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            // Display results
            foreach (UANodeElement nodeElement in nodeElementCollection)
            {
                Console.WriteLine();
                Console.WriteLine($"nodeElement.DisplayName: {nodeElement.DisplayName}");
                Console.WriteLine($"nodeElement.NodeId: {nodeElement.NodeId}");
                Console.WriteLine($"nodeElement.NodeId.ExpandedText: {nodeElement.NodeId.ExpandedText}");
            }
        }

        // Example output:
        //
        //nodeElement.DisplayName: Server
        //nodeElement.NodeId: Server
        //nodeElement.NodeId.ExpandedText: nsu = http://opcfoundation.org/UA/ ;i=2253
        //
        //nodeElement.DisplayName: Data
        //nodeElement.NodeId: nsu = http://test.org/UA/Data/ ;ns=2;i=10157
        //nodeElement.NodeId.ExpandedText: nsu = http://test.org/UA/Data/ ;ns=2;i=10157
        //
        //nodeElement.DisplayName: Boilers
        //nodeElement.NodeId: nsu = http://opcfoundation.org/UA/Boiler/ ;ns=4;i=1240
        //nodeElement.NodeId.ExpandedText: nsu = http://opcfoundation.org/UA/Boiler/ ;ns=4;i=1240
        //
        //nodeElement.DisplayName: MemoryBuffers
        //nodeElement.NodeId: nsu = http://samples.org/UA/memorybuffer ;ns=7;i=1025
        //nodeElement.NodeId.ExpandedText: nsu = http://samples.org/UA/memorybuffer ;ns=7;i=1025
    }
}
# This example shows how to obtain "data nodes" (objects, variables and properties) under the "Objects" node in the address
# space.

#requires -Version 5.1
using namespace OpcLabs.EasyOpc.UA
using namespace OpcLabs.EasyOpc.UA.OperationModel

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll"

[UAEndpointDescriptor]$endpointDescriptor =
    "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
# or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
# or "https://opcua.demo-this.com:51212/UA/SampleServer/"

# Instantiate the client object.
$client = New-Object EasyUAClient

# Obtain data nodes under "Objects" node.
try {
    $nodeElementCollection = [IEasyUAClientExtension]::BrowseDataNodes($client, $endpointDescriptor)
}
catch [UAException] {
    Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)"
    return
}

# Display results
foreach ($nodeElement in $nodeElementCollection) {
    Write-Host
    Write-Host "nodeElement.DisplayName: $($nodeElement.DisplayName)"
    Write-Host "nodeElement.NodeId: $($nodeElement.NodeId)"
    Write-Host "nodeElement.NodeId.ExpandedText: $($nodeElement.NodeId.ExpandedText)"
}


# Example output:
#
#nodeElement.DisplayName: Server
#nodeElement.NodeId: Server
#nodeElement.NodeId.ExpandedText: nsu = http://opcfoundation.org/UA/ ;i=2253
#
#nodeElement.DisplayName: Data
#nodeElement.NodeId: nsu = http://test.org/UA/Data/ ;ns=2;i=10157
#nodeElement.NodeId.ExpandedText: nsu = http://test.org/UA/Data/ ;ns=2;i=10157
#
#nodeElement.DisplayName: Boilers
#nodeElement.NodeId: nsu = http://opcfoundation.org/UA/Boiler/ ;ns=4;i=1240
#nodeElement.NodeId.ExpandedText: nsu = http://opcfoundation.org/UA/Boiler/ ;ns=4;i=1240
#
#nodeElement.DisplayName: MemoryBuffers
#nodeElement.NodeId: nsu = http://samples.org/UA/memorybuffer ;ns=7;i=1025
#nodeElement.NodeId.ExpandedText: nsu = http://samples.org/UA/memorybuffer ;ns=7;i=1025

# This example shows how to obtain all data nodes (objects and variables) under a given node of the OPC-UA address space. 
# For each node, it displays its browse name and node ID.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *


endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported)
# or 'https://opcua.demo-this.com:51212/UA/SampleServer/'

# Instantiate the client object.
client = EasyUAClient()

# Obtain data nodes under "Objects" node.
try:
    nodeElementCollection = IEasyUAClientExtension.BrowseDataNodes(client, endpointDescriptor)
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display results.
for nodeElement in nodeElementCollection:
    print()
    print('nodeElement.DisplayName: ', nodeElement.DisplayName, sep='')
    print('nodeElement.NodeId: ', nodeElement.NodeId, sep='')
    print('nodeElement.NodeId.ExpandedText: ', nodeElement.NodeId.ExpandedText, sep='')

print()
print('Finished.')
' This example shows how to obtain "data nodes" (objects, variables and properties) under the "Objects" node in the address
' space.

Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.AddressSpace
Imports OpcLabs.EasyOpc.UA.OperationModel

Namespace _EasyUAClient
    Friend Class BrowseDataNodes
        Public Shared Sub Overload1()

            ' Define which server we will work with.
            Dim endpointDescriptor As UAEndpointDescriptor =
                    "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
            ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            ' or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            ' Instantiate the client object
            Dim client = New EasyUAClient()

            ' Obtain data nodes under "Objects" node
            Dim nodeElementCollection As UANodeElementCollection
            Try
                nodeElementCollection = client.BrowseDataNodes(endpointDescriptor)
            Catch uaException As UAException
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
                Exit Sub
            End Try

            ' Display results
            For Each nodeElement As UANodeElement In nodeElementCollection
                Console.WriteLine()
                Console.WriteLine("nodeElement.NodeId: {0}", nodeElement.NodeId)
                Console.WriteLine("nodeElement.DisplayName: {0}", nodeElement.DisplayName)
            Next nodeElement

            ' Example output:
            '
            'nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2253
            'nodeElement.DisplayName: Server
            '
            'nodeElement.NodeId: nsu=http://test.org/UA/Data/ ;i=10157
            'nodeElement.DisplayName: Data
            '
            'nodeElement.NodeId: nsu=http://opcfoundation.org/UA/Boiler/;i=1240
            'nodeElement.DisplayName: Boilers
            '
            'nodeElement.NodeId: nsu=http://samples.org/UA/memorybuffer;i=1025
            'nodeElement.DisplayName: MemoryBuffers            
        End Sub
    End Class
End Namespace

COM

// This example shows how to obtain all data nodes (objects and variables) under a given node of the OPC-UA address space.
// For each node, it displays its browse name and node ID.

#include "stdafx.h"    // Includes "QuickOpc.h", and other commonly used files
#include "BrowseDataNodes.h"

namespace _EasyUAClient
{
    void BrowseDataNodes::Main()
    {
        // Initialize the COM library
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        {
            // Instantiate the client object
            _EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));

            // Perform the operation
            _UANodeElementCollectionPtr NodeElementsPtr = ClientPtr->BrowseDataNodes(
                //L"http://opcua.demo-this.com:51211/UA/SampleServer", 
                L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer",
                L"nsu=http://test.org/UA/Data/ ;i=10791");
    
            // Display results
            IEnumVARIANTPtr EnumNodeElementPtr = NodeElementsPtr->GetEnumerator();
            _variant_t vNodeElement;
            while (EnumNodeElementPtr->Next(1, &vNodeElement, NULL) == S_OK)
            {
                _UANodeElementPtr NodeElementPtr(vNodeElement);
                _tprintf(_T("%s: "), (LPCTSTR)CW2CT(NodeElementPtr->BrowseName->ToString));
                _tprintf(_T("%s\n"), (LPCTSTR)CW2CT(NodeElementPtr->NodeId->ToString));
                vNodeElement.Clear();
            }
        }
         // Release all interface pointers BEFORE calling CoUninitialize()
        CoUninitialize();
    }
}
// This example shows how to obtain all data nodes (objects and variables)
// under a given node of the OPC-UA address space. For each node, it displays
// its browse name and node ID.

class procedure BrowseDataNodes.Main;
var
  Client: EasyUAClient;
  Count: Cardinal;
  Element: OleVariant;
  NodeElement: _UANodeElement;
  NodeElementEnumerator: IEnumVariant;
  NodeElements: _UANodeElementCollection;
begin
  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  NodeElements := Client.BrowseDataNodes(
    //'http://opcua.demo-this.com:51211/UA/SampleServer',
    'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
    'nsu=http://test.org/UA/Data/ ;i=10791');

  NodeElementEnumerator := NodeElements.GetEnumerator;
  while (NodeElementEnumerator.Next(1, Element, Count) = S_OK) do
  begin
    NodeElement := IUnknown(Element) as _UANodeElement;
    WriteLn(NodeElement.BrowseName.ToString, ': ', NodeElement.NodeId.ToString);
  end;
end;
// This example shows how to obtain all data nodes (objects and variables)
// under a given node of the OPC-UA address space. For each node, it displays
// its browse name and node ID.

class procedure BrowseDataNodes.Main;
var
  Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
  Count: Cardinal;
  Element: OleVariant;
  NodeElement: _UANodeElement;
  NodeElementEnumerator: IEnumVariant;
  NodeElements: _UANodeElementCollection;
begin
  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  try
    NodeElements := Client.BrowseDataNodes(
      //'http://opcua.demo-this.com:51211/UA/SampleServer',
      //'https://opcua.demo-this.com:51212/UA/SampleServer/',
      'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
      'nsu=http://test.org/UA/Data/ ;i=10791');
  except
    on E: EOleException do
    begin
      WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
      Exit;
    end;
  end;

  NodeElementEnumerator := NodeElements.GetEnumerator;
  while (NodeElementEnumerator.Next(1, Element, Count) = S_OK) do
  begin
    NodeElement := IUnknown(Element) as _UANodeElement;
    WriteLn(NodeElement.BrowseName.ToString, ': ', NodeElement.NodeId.ToString);
  end;
end;
// This example shows how to obtain all data nodes (objects and variables) under a given node of the OPC-UA address space. 
// For each node, it displays its browse name and node ID.

// Instantiate the client object
$Client = new COM("OpcLabs.EasyOpc.UA.EasyUAClient");

// Perform the operation
try
{
    $NodeElements = $Client->BrowseDataNodes(
        //"http://opcua.demo-this.com:51211/UA/SampleServer", 
        "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", 
        "nsu=http://test.org/UA/Data/ ;i=10791");
}
catch (com_exception $e)
{
    printf("*** Failure: %s\n", $e->getMessage());
    Exit();
}

// Display results
foreach ($NodeElements as $NodeElement)
{
    printf("s: s\n", $NodeElement->BrowseName, $NodeElement->NodeId);
}
// This example shows how to obtain all data nodes (objects and variables) under a given node of the OPC-UA address space.
// For each node, it displays its browse name and node ID.

mle_outputtext.Text = ""

// Instantiate the client object
OLEObject client
client = CREATE OLEObject
client.ConnectToNewObject("OpcLabs.EasyOpc.UA.EasyUAClient")

// Perform the operation
OLEObject nodeElements
TRY
    nodeElements = client.BrowseDataNodes("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10791")
CATCH (OLERuntimeError oleRuntimeError)
    mle_outputtext.Text = mle_outputtext.Text + "*** Failure: " + oleRuntimeError.Description + "~r~n"
    RETURN
END TRY

// Display results
Int i
FOR i = 0 TO nodeElements.Count - 1
    OLEObject nodeElement
    nodeElement = nodeElements.Item[i]
    mle_outputtext.Text = mle_outputtext.Text + "~r~n"
    mle_outputtext.Text = mle_outputtext.Text + "nodeElement.NodeId: " + nodeElement.NodeId.DisplayString + "~r~n"
    mle_outputtext.Text = mle_outputtext.Text + "nodeElement.DisplayName: " + nodeElement.DisplayName + "~r~n"
NEXT

mle_outputtext.Text = mle_outputtext.Text + "~r~n" 
mle_outputtext.Text = mle_outputtext.Text + "Finished." + "~r~n" 
# This example shows how to obtain all data nodes (objects and variables) under a given node of the OPC-UA address space. 
# For each node, it displays its browse name and node ID.

# The Python for Windows (pywin32) extensions package is needed. Install it using "pip install pypiwin32".
# CAUTION: We now recommend using Python.NET package instead. Full set of examples with Python.NET is available!
import win32com.client
from pywintypes import com_error

# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.UA.EasyUAClient') 

# Perform the operation
try:
    nodeElements = client.BrowseDataNodes('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer', 'nsu=http://test.org/UA/Data/ ;i=10791')
except com_error as e:
    print('*** Failure: ' + e.args[2][1] + ': ' + e.args[2][2])
    exit()

# Display results
for nodeElement in nodeElements:
    print(nodeElement.BrowseName, ': ', nodeElement.NodeId)
Rem This example shows how to obtain all data nodes (objects and variables) under a given node of the OPC-UA address space.
Rem For each node, it displays its browse name and node ID.

Public Sub BrowseDataNodes_Main_Command_Click()
    OutputText = ""

    ' Instantiate the client object
    Dim Client As New EasyUAClient

    ' Perform the operation
    On Error Resume Next
    Dim NodeElements As UANodeElementCollection
    Set NodeElements = Client.BrowseDataNodes("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10791")
    If Err.Number <> 0 Then
        OutputText = OutputText & "*** Failure: " & Err.Source & ": " & Err.Description & vbCrLf
        Exit Sub
    End If
    On Error GoTo 0

    ' Display results
    Dim NodeElement: For Each NodeElement In NodeElements
        OutputText = OutputText & NodeElement.BrowseName & ": " & NodeElement.NodeId & vbCrLf
    Next
End Sub
Rem This example shows how to obtain all data nodes (objects and variables) under a given node of the OPC-UA address space. 
Rem For each node, it displays its browse name and node ID.

Option Explicit

' Instantiate the client object
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")

' Perform the operation
On Error Resume Next
Dim NodeElements: Set NodeElements = Client.BrowseDataNodes("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10791")
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

' Display results
Dim NodeElement: For Each NodeElement In NodeElements
    WScript.Echo NodeElement.BrowseName & ": " & NodeElement.NodeId
Next

 

See Also

Conceptual

Examples - OPC Data Access